package com.hadoop.mapReduce.wordCountMine;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 *
 * 作用：存数据，取数据
 * 自定义上下文，其实就是缓存
 * 上下文:仓库（集合：数据结构+算法），放置各种东西
 *
 */
public class _01MyContext {

    private static Map<Object, Object> cacheMap = new HashMap<Object, Object>();

    public Map<Object, Object> getCacheMap() {
        return cacheMap;
    }

    /**
     * 写数据到缓存中去
     * @param key 单词
     * @param value 次数
     */
    public void write(Object key, Object value) {
        cacheMap.put(key, value);
    }

    /**
     * 从缓存中获取值
     * @param key 单词

     */
    public Object get(Object key) {


        return cacheMap.get(key);



    }

    public static void main(String[] args) {
        cacheMap.put("mr xiaoxia",1);
        cacheMap.put("mr gao",1);
        cacheMap.put("mr cheng",0);
        cacheMap.put("mr cheng",0);




        System.out.println(cacheMap.get("mr cheng"));
        System.out.println(cacheMap.get("mr xiaoxia"));
        System.out.println(cacheMap.get("mr gao"));
        System.out.println(cacheMap.get("mr cong"));

        Set<Map.Entry<Object, Object>> entries = cacheMap.entrySet();
        for(Map.Entry<Object, Object> entry : entries) {
            //key->hadoop value-> 2
            System.out.println(entry.getKey().toString() + " \t " + entry.getValue() + "\n");
        }

    }

}
